home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_elisp-manual-19.idb / usr / freeware / info / elisp-25.z / elisp-25 (.txt)
GNU Info File  |  1998-05-26  |  50KB  |  933 lines

  1. This is Info file elisp, produced by Makeinfo-1.63 from the input file
  2. elisp.texi.
  3.    This version is the edition 2.4.2 of the GNU Emacs Lisp Reference
  4. Manual.  It corresponds to Emacs Version 19.34.
  5.    Published by the Free Software Foundation 59 Temple Place, Suite 330
  6. Boston, MA  02111-1307  USA
  7.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996 Free Software
  8. Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that the
  14. entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the section entitled "GNU General Public License" is included
  23. exactly as in the original, and provided that the entire resulting
  24. derived work is distributed under the terms of a permission notice
  25. identical to this one.
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that the section entitled "GNU General Public License"
  29. may be included in a translation approved by the Free Software
  30. Foundation instead of in the original English.
  31. File: elisp,  Node: Character Motion,  Next: Word Motion,  Up: Motion
  32. Motion by Characters
  33. --------------------
  34.    These functions move point based on a count of characters.
  35. `goto-char' is the fundamental primitive; the other functions use that.
  36.  - Command: goto-char POSITION
  37.      This function sets point in the current buffer to the value
  38.      POSITION.  If POSITION is less than 1, it moves point to the
  39.      beginning of the buffer.  If POSITION is greater than the length
  40.      of the buffer, it moves point to the end.
  41.      If narrowing is in effect, POSITION still counts from the
  42.      beginning of the buffer, but point cannot go outside the accessible
  43.      portion.  If POSITION is out of range, `goto-char' moves point to
  44.      the beginning or the end of the accessible portion.
  45.      When this function is called interactively, POSITION is the
  46.      numeric prefix argument, if provided; otherwise it is read from the
  47.      minibuffer.
  48.      `goto-char' returns POSITION.
  49.  - Command: forward-char &optional COUNT
  50.      This function moves point COUNT characters forward, towards the
  51.      end of the buffer (or backward, towards the beginning of the
  52.      buffer, if COUNT is negative).  If the function attempts to move
  53.      point past the beginning or end of the buffer (or the limits of
  54.      the accessible portion, when narrowing is in effect), an error is
  55.      signaled with error code `beginning-of-buffer' or `end-of-buffer'.
  56.      In an interactive call, COUNT is the numeric prefix argument.
  57.  - Command: backward-char &optional COUNT
  58.      This function moves point COUNT characters backward, towards the
  59.      beginning of the buffer (or forward, towards the end of the
  60.      buffer, if COUNT is negative).  If the function attempts to move
  61.      point past the beginning or end of the buffer (or the limits of
  62.      the accessible portion, when narrowing is in effect), an error is
  63.      signaled with error code `beginning-of-buffer' or `end-of-buffer'.
  64.      In an interactive call, COUNT is the numeric prefix argument.
  65. File: elisp,  Node: Word Motion,  Next: Buffer End Motion,  Prev: Character Motion,  Up: Motion
  66. Motion by Words
  67. ---------------
  68.    These functions for parsing words use the syntax table to decide
  69. whether a given character is part of a word.  *Note Syntax Tables::.
  70.  - Command: forward-word COUNT
  71.      This function moves point forward COUNT words (or backward if
  72.      COUNT is negative).  Normally it returns `t'.  If this motion
  73.      encounters the beginning or end of the buffer, or the limits of the
  74.      accessible portion when narrowing is in effect, point stops there
  75.      and the value is `nil'.
  76.      In an interactive call, COUNT is set to the numeric prefix
  77.      argument.
  78.  - Command: backward-word COUNT
  79.      This function is just like `forward-word', except that it moves
  80.      backward until encountering the front of a word, rather than
  81.      forward.
  82.      In an interactive call, COUNT is set to the numeric prefix
  83.      argument.
  84.      This function is rarely used in programs, as it is more efficient
  85.      to call `forward-word' with a negative argument.
  86.  - Variable: words-include-escapes
  87.      This variable affects the behavior of `forward-word' and everything
  88.      that uses it.  If it is non-`nil', then characters in the "escape"
  89.      and "character quote" syntax classes count as part of words.
  90.      Otherwise, they do not.
  91. File: elisp,  Node: Buffer End Motion,  Next: Text Lines,  Prev: Word Motion,  Up: Motion
  92. Motion to an End of the Buffer
  93. ------------------------------
  94.    To move point to the beginning of the buffer, write:
  95.      (goto-char (point-min))
  96. Likewise, to move to the end of the buffer, use:
  97.      (goto-char (point-max))
  98.    Here are two commands that users use to do these things.  They are
  99. documented here to warn you not to use them in Lisp programs, because
  100. they set the mark and display messages in the echo area.
  101.  - Command: beginning-of-buffer &optional N
  102.      This function moves point to the beginning of the buffer (or the
  103.      limits of the accessible portion, when narrowing is in effect),
  104.      setting the mark at the previous position.  If N is non-`nil',
  105.      then it puts point N tenths of the way from the beginning of the
  106.      buffer.
  107.      In an interactive call, N is the numeric prefix argument, if
  108.      provided; otherwise N defaults to `nil'.
  109.      Don't use this function in Lisp programs!
  110.  - Command: end-of-buffer &optional N
  111.      This function moves point to the end of the buffer (or the limits
  112.      of the accessible portion, when narrowing is in effect), setting
  113.      the mark at the previous position.  If N is non-`nil', then it puts
  114.      point N tenths of the way from the end of the buffer.
  115.      In an interactive call, N is the numeric prefix argument, if
  116.      provided; otherwise N defaults to `nil'.
  117.      Don't use this function in Lisp programs!
  118. File: elisp,  Node: Text Lines,  Next: Screen Lines,  Prev: Buffer End Motion,  Up: Motion
  119. Motion by Text Lines
  120. --------------------
  121.    Text lines are portions of the buffer delimited by newline
  122. characters, which are regarded as part of the previous line.  The first
  123. text line begins at the beginning of the buffer, and the last text line
  124. ends at the end of the buffer whether or not the last character is a
  125. newline.  The division of the buffer into text lines is not affected by
  126. the width of the window, by line continuation in display, or by how
  127. tabs and control characters are displayed.
  128.  - Command: goto-line LINE
  129.      This function moves point to the front of the LINEth line,
  130.      counting from line 1 at beginning of the buffer.  If LINE is less
  131.      than 1, it moves point to the beginning of the buffer.  If LINE is
  132.      greater than the number of lines in the buffer, it moves point to
  133.      the end of the buffer--that is, the *end of the last line* of the
  134.      buffer.  This is the only case in which `goto-line' does not
  135.      necessarily move to the beginning of a line.
  136.      If narrowing is in effect, then LINE still counts from the
  137.      beginning of the buffer, but point cannot go outside the accessible
  138.      portion.  So `goto-line' moves point to the beginning or end of the
  139.      accessible portion, if the line number specifies an inaccessible
  140.      position.
  141.      The return value of `goto-line' is the difference between LINE and
  142.      the line number of the line to which point actually was able to
  143.      move (in the full buffer, before taking account of narrowing).
  144.      Thus, the value is positive if the scan encounters the real end of
  145.      the buffer.  The value is zero if scan encounters the end of the
  146.      accessible portion but not the real end of the buffer.
  147.      In an interactive call, LINE is the numeric prefix argument if one
  148.      has been provided.  Otherwise LINE is read in the minibuffer.
  149.  - Command: beginning-of-line &optional COUNT
  150.      This function moves point to the beginning of the current line.
  151.      With an argument COUNT not `nil' or 1, it moves forward COUNT-1
  152.      lines and then to the beginning of the line.
  153.      If this function reaches the end of the buffer (or of the
  154.      accessible portion, if narrowing is in effect), it positions point
  155.      there.  No error is signaled.
  156.  - Command: end-of-line &optional COUNT
  157.      This function moves point to the end of the current line.  With an
  158.      argument COUNT not `nil' or 1, it moves forward COUNT-1 lines and
  159.      then to the end of the line.
  160.      If this function reaches the end of the buffer (or of the
  161.      accessible portion, if narrowing is in effect), it positions point
  162.      there.  No error is signaled.
  163.  - Command: forward-line &optional COUNT
  164.      This function moves point forward COUNT lines, to the beginning of
  165.      the line.  If COUNT is negative, it moves point -COUNT lines
  166.      backward, to the beginning of a line.  If COUNT is zero, it moves
  167.      point to the beginning of the current line.
  168.      If `forward-line' encounters the beginning or end of the buffer (or
  169.      of the accessible portion) before finding that many lines, it sets
  170.      point there.  No error is signaled.
  171.      `forward-line' returns the difference between COUNT and the number
  172.      of lines actually moved.  If you attempt to move down five lines
  173.      from the beginning of a buffer that has only three lines, point
  174.      stops at the end of the last line, and the value will be 2.
  175.      In an interactive call, COUNT is the numeric prefix argument.
  176.  - Function: count-lines START END
  177.      This function returns the number of lines between the positions
  178.      START and END in the current buffer.  If START and END are equal,
  179.      then it returns 0.  Otherwise it returns at least 1, even if START
  180.      and END are on the same line.  This is because the text between
  181.      them, considered in isolation, must contain at least one line
  182.      unless it is empty.
  183.      Here is an example of using `count-lines':
  184.           (defun current-line ()
  185.             "Return the vertical position of point..."
  186.             (+ (count-lines (window-start) (point))
  187.                (if (= (current-column) 0) 1 0)
  188.                -1))
  189.    Also see the functions `bolp' and `eolp' in *Note Near Point::.
  190. These functions do not move point, but test whether it is already at the
  191. beginning or end of a line.
  192. File: elisp,  Node: Screen Lines,  Next: List Motion,  Prev: Text Lines,  Up: Motion
  193. Motion by Screen Lines
  194. ----------------------
  195.    The line functions in the previous section count text lines,
  196. delimited only by newline characters.  By contrast, these functions
  197. count screen lines, which are defined by the way the text appears on
  198. the screen.  A text line is a single screen line if it is short enough
  199. to fit the width of the selected window, but otherwise it may occupy
  200. several screen lines.
  201.    In some cases, text lines are truncated on the screen rather than
  202. continued onto additional screen lines.  In these cases,
  203. `vertical-motion' moves point much like `forward-line'.  *Note
  204. Truncation::.
  205.    Because the width of a given string depends on the flags that control
  206. the appearance of certain characters, `vertical-motion' behaves
  207. differently, for a given piece of text, depending on the buffer it is
  208. in, and even on the selected window (because the width, the truncation
  209. flag, and display table may vary between windows).  *Note Usual
  210. Display::.
  211.    These functions scan text to determine where screen lines break, and
  212. thus take time proportional to the distance scanned.  If you intend to
  213. use them heavily, Emacs provides caches which may improve the
  214. performance of your code.  *Note cache-long-line-scans: Text Lines.
  215.  - Function: vertical-motion COUNT &optional WINDOW
  216.      This function moves point to the start of the screen line COUNT
  217.      screen lines down from the screen line containing point.  If COUNT
  218.      is negative, it moves up instead.
  219.      `vertical-motion' returns the number of lines moved.  The value may
  220.      be less in absolute value than COUNT if the beginning or end of
  221.      the buffer was reached.
  222.      The window WINDOW is used for obtaining parameters such as the
  223.      width, the horizontal scrolling, and the display table.  But
  224.      `vertical-motion' always operates on the current buffer, even if
  225.      WINDOW currently displays some other buffer.
  226.  - Command: move-to-window-line COUNT
  227.      This function moves point with respect to the text currently
  228.      displayed in the selected window.  It moves point to the beginning
  229.      of the screen line COUNT screen lines from the top of the window.
  230.      If COUNT is negative, that specifies a position -COUNT lines from
  231.      the bottom (or the last line of the buffer, if the buffer ends
  232.      above the specified screen position).
  233.      If COUNT is `nil', then point moves to the beginning of the line
  234.      in the middle of the window.  If the absolute value of COUNT is
  235.      greater than the size of the window, then point moves to the place
  236.      that would appear on that screen line if the window were tall
  237.      enough.  This will probably cause the next redisplay to scroll to
  238.      bring that location onto the screen.
  239.      In an interactive call, COUNT is the numeric prefix argument.
  240.      The value returned is the window line number point has moved to,
  241.      with the top line in the window numbered 0.
  242.  - Function: compute-motion FROM FROMPOS TO TOPOS WIDTH OFFSETS WINDOW
  243.      This function scans the current buffer, calculating screen
  244.      positions.  It scans the buffer forward from position FROM,
  245.      assuming that is at screen coordinates FROMPOS, to position TO or
  246.      coordinates TOPOS, whichever comes first.  It returns the ending
  247.      buffer position and screen coordinates.
  248.      The coordinate arguments FROMPOS and TOPOS are cons cells of the
  249.      form `(HPOS . VPOS)'.
  250.      The argument WIDTH is the number of columns available to display
  251.      text; this affects handling of continuation lines.  Use the value
  252.      returned by `window-width' for the window of your choice;
  253.      normally, use `(window-width WINDOW)'.
  254.      The argument OFFSETS is either `nil' or a cons cell of the form
  255.      `(HSCROLL . TAB-OFFSET)'.  Here HSCROLL is the number of columns
  256.      not being displayed at the left margin; most callers get this from
  257.      `window-hscroll'.  Meanwhile, TAB-OFFSET is the offset between
  258.      column numbers on the screen and column numbers in the buffer.
  259.      This can be nonzero in a continuation line, when the previous
  260.      screen lines' widths do not add up to a multiple of `tab-width'.
  261.      It is always zero in a non-continuation line.
  262.      The window WINDOW serves only to specify which display table to
  263.      use.  `compute-motion' always operates on the current buffer,
  264.      regardless of what buffer is displayed in WINDOW.
  265.      The return value is a list of five elements:
  266.           (POS VPOS HPOS PREVHPOS CONTIN)
  267.      Here POS is the buffer position where the scan stopped, VPOS is
  268.      the vertical screen position, and HPOS is the horizontal screen
  269.      position.
  270.      The result PREVHPOS is the horizontal position one character back
  271.      from POS.  The result CONTIN is `t' if the last line was continued
  272.      after (or within) the previous character.
  273.      For example, to find the buffer position of column COL of line
  274.      LINE of a certain window, pass the window's display start location
  275.      as FROM and the window's upper-left coordinates as FROMPOS.  Pass
  276.      the buffer's `(point-max)' as TO, to limit the scan to the end of
  277.      the accessible portion of the buffer, and pass LINE and COL as
  278.      TOPOS.  Here's a function that does this:
  279.           (defun coordinates-of-position (col line)
  280.             (car (compute-motion (window-start)
  281.                                  '(0 . 0)
  282.                                  (point-max)
  283.                                  (cons col line)
  284.                                  (window-width)
  285.                                  (cons (window-hscroll) 0)
  286.                                  (selected-window))))
  287.      When you use `compute-motion' for the minibuffer, you need to use
  288.      `minibuffer-prompt-width' to get the horizontal position of the
  289.      beginning of the first screen line.  *Note Minibuffer Misc::.
  290. File: elisp,  Node: List Motion,  Next: Skipping Characters,  Prev: Screen Lines,  Up: Motion
  291. Moving over Balanced Expressions
  292. --------------------------------
  293.    Here are several functions concerned with balanced-parenthesis
  294. expressions (also called "sexps" in connection with moving across them
  295. in Emacs).  The syntax table controls how these functions interpret
  296. various characters; see *Note Syntax Tables::.  *Note Parsing
  297. Expressions::, for lower-level primitives for scanning sexps or parts of
  298. sexps.  For user-level commands, see *Note Lists Commands: (emacs)Lists
  299. Commands.
  300.  - Command: forward-list ARG
  301.      This function moves forward across ARG balanced groups of
  302.      parentheses.  (Other syntactic entities such as words or paired
  303.      string quotes are ignored.)
  304.  - Command: backward-list ARG
  305.      This function moves backward across ARG balanced groups of
  306.      parentheses.  (Other syntactic entities such as words or paired
  307.      string quotes are ignored.)
  308.  - Command: up-list ARG
  309.      This function moves forward out of ARG levels of parentheses.  A
  310.      negative argument means move backward but still to a less deep
  311.      spot.
  312.  - Command: down-list ARG
  313.      This function moves forward into ARG levels of parentheses.  A
  314.      negative argument means move backward but still go deeper in
  315.      parentheses (-ARG levels).
  316.  - Command: forward-sexp ARG
  317.      This function moves forward across ARG balanced expressions.
  318.      Balanced expressions include both those delimited by parentheses
  319.      and other kinds, such as words and string constants.  For example,
  320.           ---------- Buffer: foo ----------
  321.           (concat-!- "foo " (car x) y z)
  322.           ---------- Buffer: foo ----------
  323.           
  324.           (forward-sexp 3)
  325.                => nil
  326.           
  327.           ---------- Buffer: foo ----------
  328.           (concat "foo " (car x) y-!- z)
  329.           ---------- Buffer: foo ----------
  330.  - Command: backward-sexp ARG
  331.      This function moves backward across ARG balanced expressions.
  332.  - Command: beginning-of-defun ARG
  333.      This function moves back to the ARGth beginning of a defun.  If
  334.      ARG is negative, this actually moves forward, but it still moves
  335.      to the beginning of a defun, not to the end of one.
  336.  - Command: end-of-defun ARG
  337.      This function moves forward to the ARGth end of a defun.  If ARG
  338.      is negative, this actually moves backward, but it still moves to
  339.      the end of a defun, not to the beginning of one.
  340.  - User Option: defun-prompt-regexp
  341.      If non-`nil', this variable holds a regular expression that
  342.      specifies what text can appear before the open-parenthesis that
  343.      starts a defun.  That is to say, a defun begins on a line that
  344.      starts with a match for this regular expression, followed by a
  345.      character with open-parenthesis syntax.
  346. File: elisp,  Node: Skipping Characters,  Prev: List Motion,  Up: Motion
  347. Skipping Characters
  348. -------------------
  349.    The following two functions move point over a specified set of
  350. characters.  For example, they are often used to skip whitespace.  For
  351. related functions, see *Note Motion and Syntax::.
  352.  - Function: skip-chars-forward CHARACTER-SET &optional LIMIT
  353.      This function moves point in the current buffer forward, skipping
  354.      over a given set of characters.  It examines the character
  355.      following point, then advances point if the character matches
  356.      CHARACTER-SET.  This continues until it reaches a character that
  357.      does not match.  The function returns `nil'.
  358.      The argument CHARACTER-SET is like the inside of a `[...]' in a
  359.      regular expression except that `]' is never special and `\' quotes
  360.      `^', `-' or `\'.  Thus, `"a-zA-Z"' skips over all letters,
  361.      stopping before the first nonletter, and `"^a-zA-Z"' skips
  362.      nonletters stopping before the first letter.  *Note Regular
  363.      Expressions::.
  364.      If LIMIT is supplied (it must be a number or a marker), it
  365.      specifies the maximum position in the buffer that point can be
  366.      skipped to.  Point will stop at or before LIMIT.
  367.      In the following example, point is initially located directly
  368.      before the `T'.  After the form is evaluated, point is located at
  369.      the end of that line (between the `t' of `hat' and the newline).
  370.      The function skips all letters and spaces, but not newlines.
  371.           ---------- Buffer: foo ----------
  372.           I read "-!-The cat in the hat
  373.           comes back" twice.
  374.           ---------- Buffer: foo ----------
  375.           
  376.           (skip-chars-forward "a-zA-Z ")
  377.                => nil
  378.           
  379.           ---------- Buffer: foo ----------
  380.           I read "The cat in the hat-!-
  381.           comes back" twice.
  382.           ---------- Buffer: foo ----------
  383.  - Function: skip-chars-backward CHARACTER-SET &optional LIMIT
  384.      This function moves point backward, skipping characters that match
  385.      CHARACTER-SET, until LIMIT.  It just like `skip-chars-forward'
  386.      except for the direction of motion.
  387. File: elisp,  Node: Excursions,  Next: Narrowing,  Prev: Motion,  Up: Positions
  388. Excursions
  389. ==========
  390.    It is often useful to move point "temporarily" within a localized
  391. portion of the program, or to switch buffers temporarily.  This is
  392. called an "excursion", and it is done with the `save-excursion' special
  393. form.  This construct saves the current buffer and its values of point
  394. and the mark so they can be restored after the completion of the
  395. excursion.
  396.    The forms for saving and restoring the configuration of windows are
  397. described elsewhere (see *Note Window Configurations::, and *note Frame
  398. Configurations::.).
  399.  - Special Form: save-excursion FORMS...
  400.      The `save-excursion' special form saves the identity of the current
  401.      buffer and the values of point and the mark in it, evaluates
  402.      FORMS, and finally restores the buffer and its saved values of
  403.      point and the mark.  All three saved values are restored even in
  404.      case of an abnormal exit via `throw' or error (*note Nonlocal
  405.      Exits::.).
  406.      The `save-excursion' special form is the standard way to switch
  407.      buffers or move point within one part of a program and avoid
  408.      affecting the rest of the program.  It is used more than 500 times
  409.      in the Lisp sources of Emacs.
  410.      `save-excursion' does not save the values of point and the mark for
  411.      other buffers, so changes in other buffers remain in effect after
  412.      `save-excursion' exits.
  413.      Likewise, `save-excursion' does not restore window-buffer
  414.      correspondences altered by functions such as `switch-to-buffer'.
  415.      One way to restore these correspondences, and the selected window,
  416.      is to use `save-window-excursion' inside `save-excursion' (*note
  417.      Window Configurations::.).
  418.      The value returned by `save-excursion' is the result of the last of
  419.      FORMS, or `nil' if no FORMS are given.
  420.           (save-excursion
  421.             FORMS)
  422.           ==
  423.           (let ((old-buf (current-buffer))
  424.                 (old-pnt (point-marker))
  425.                 (old-mark (copy-marker (mark-marker))))
  426.             (unwind-protect
  427.                 (progn FORMS)
  428.               (set-buffer old-buf)
  429.               (goto-char old-pnt)
  430.               (set-marker (mark-marker) old-mark)))
  431. File: elisp,  Node: Narrowing,  Prev: Excursions,  Up: Positions
  432. Narrowing
  433. =========
  434.    "Narrowing" means limiting the text addressable by Emacs editing
  435. commands to a limited range of characters in a buffer.  The text that
  436. remains addressable is called the "accessible portion" of the buffer.
  437.    Narrowing is specified with two buffer positions which become the
  438. beginning and end of the accessible portion.  For most editing commands
  439. and most Emacs primitives, these positions replace the values of the
  440. beginning and end of the buffer.  While narrowing is in effect, no text
  441. outside the accessible portion is displayed, and point cannot move
  442. outside the accessible portion.
  443.    Values such as positions or line numbers, which usually count from
  444. the beginning of the buffer, do so despite narrowing, but the functions
  445. which use them refuse to operate on text that is inaccessible.
  446.    The commands for saving buffers are unaffected by narrowing; they
  447. save the entire buffer regardless of any narrowing.
  448.  - Command: narrow-to-region START END
  449.      This function sets the accessible portion of the current buffer to
  450.      start at START and end at END.  Both arguments should be character
  451.      positions.
  452.      In an interactive call, START and END are set to the bounds of the
  453.      current region (point and the mark, with the smallest first).
  454.  - Command: narrow-to-page MOVE-COUNT
  455.      This function sets the accessible portion of the current buffer to
  456.      include just the current page.  An optional first argument
  457.      MOVE-COUNT non-`nil' means to move forward or backward by
  458.      MOVE-COUNT pages and then narrow.  The variable `page-delimiter'
  459.      specifies where pages start and end (*note Standard Regexps::.).
  460.      In an interactive call, MOVE-COUNT is set to the numeric prefix
  461.      argument.
  462.  - Command: widen
  463.      This function cancels any narrowing in the current buffer, so that
  464.      the entire contents are accessible.  This is called "widening".
  465.      It is equivalent to the following expression:
  466.           (narrow-to-region 1 (1+ (buffer-size)))
  467.  - Special Form: save-restriction BODY...
  468.      This special form saves the current bounds of the accessible
  469.      portion, evaluates the BODY forms, and finally restores the saved
  470.      bounds, thus restoring the same state of narrowing (or absence
  471.      thereof) formerly in effect.  The state of narrowing is restored
  472.      even in the event of an abnormal exit via `throw' or error (*note
  473.      Nonlocal Exits::.).  Therefore, this construct is a clean way to
  474.      narrow a buffer temporarily.
  475.      The value returned by `save-restriction' is that returned by the
  476.      last form in BODY, or `nil' if no body forms were given.
  477.      *Caution:* it is easy to make a mistake when using the
  478.      `save-restriction' construct.  Read the entire description here
  479.      before you try it.
  480.      If BODY changes the current buffer, `save-restriction' still
  481.      restores the restrictions on the original buffer (the buffer whose
  482.      restructions it saved from), but it does not restore the identity
  483.      of the current buffer.
  484.      `save-restriction' does *not* restore point and the mark; use
  485.      `save-excursion' for that.  If you use both `save-restriction' and
  486.      `save-excursion' together, `save-excursion' should come first (on
  487.      the outside).  Otherwise, the old point value would be restored
  488.      with temporary narrowing still in effect.  If the old point value
  489.      were outside the limits of the temporary narrowing, this would
  490.      fail to restore it accurately.
  491.      The `save-restriction' special form records the values of the
  492.      beginning and end of the accessible portion as distances from the
  493.      beginning and end of the buffer.  In other words, it records the
  494.      amount of inaccessible text before and after the accessible
  495.      portion.
  496.      This method yields correct results if BODY does further narrowing.
  497.      However, `save-restriction' can become confused if the body widens
  498.      and then make changes outside the range of the saved narrowing.
  499.      When this is what you want to do, `save-restriction' is not the
  500.      right tool for the job.  Here is what you must use instead:
  501.           (let ((beg (point-min-marker))
  502.                 (end (point-max-marker)))
  503.             (unwind-protect
  504.                 (progn BODY)
  505.               (save-excursion
  506.                 (set-buffer (marker-buffer beg))
  507.                 (narrow-to-region beg end))))
  508.      Here is a simple example of correct use of `save-restriction':
  509.           ---------- Buffer: foo ----------
  510.           This is the contents of foo
  511.           This is the contents of foo
  512.           This is the contents of foo-!-
  513.           ---------- Buffer: foo ----------
  514.           
  515.           (save-excursion
  516.             (save-restriction
  517.               (goto-char 1)
  518.               (forward-line 2)
  519.               (narrow-to-region 1 (point))
  520.               (goto-char (point-min))
  521.               (replace-string "foo" "bar")))
  522.           
  523.           ---------- Buffer: foo ----------
  524.           This is the contents of bar
  525.           This is the contents of bar
  526.           This is the contents of foo-!-
  527.           ---------- Buffer: foo ----------
  528. File: elisp,  Node: Markers,  Next: Text,  Prev: Positions,  Up: Top
  529. Markers
  530. *******
  531.    A "marker" is a Lisp object used to specify a position in a buffer
  532. relative to the surrounding text.  A marker changes its offset from the
  533. beginning of the buffer automatically whenever text is inserted or
  534. deleted, so that it stays with the two characters on either side of it.
  535. * Menu:
  536. * Overview of Markers::      The components of a marker, and how it relocates.
  537. * Predicates on Markers::    Testing whether an object is a marker.
  538. * Creating Markers::         Making empty markers or markers at certain places.
  539. * Information from Markers:: Finding the marker's buffer or character position.
  540. * Changing Markers::         Moving the marker to a new buffer or position.
  541. * The Mark::                 How "the mark" is implemented with a marker.
  542. * The Region::               How to access "the region".
  543. File: elisp,  Node: Overview of Markers,  Next: Predicates on Markers,  Up: Markers
  544. Overview of Markers
  545. ===================
  546.    A marker specifies a buffer and a position in that buffer.  The
  547. marker can be used to represent a position in the functions that
  548. require one, just as an integer could be used.  *Note Positions::, for
  549. a complete description of positions.
  550.    A marker has two attributes: the marker position, and the marker
  551. buffer.  The marker position is an integer that is equivalent (at a
  552. given time) to the marker as a position in that buffer.  But the
  553. marker's position value can change often during the life of the marker.
  554. Insertion and deletion of text in the buffer relocate the marker.  The
  555. idea is that a marker positioned between two characters remains between
  556. those two characters despite insertion and deletion elsewhere in the
  557. buffer.  Relocation changes the integer equivalent of the marker.
  558.    Deleting text around a marker's position leaves the marker between
  559. the characters immediately before and after the deleted text.  Inserting
  560. text at the position of a marker normally leaves the marker in front of
  561. the new text--unless it is inserted with `insert-before-markers' (*note
  562. Insertion::.).
  563.    Insertion and deletion in a buffer must check all the markers and
  564. relocate them if necessary.  This slows processing in a buffer with a
  565. large number of markers.  For this reason, it is a good idea to make a
  566. marker point nowhere if you are sure you don't need it any more.
  567. Unreferenced markers are garbage collected eventually, but until then
  568. will continue to use time if they do point somewhere.
  569.    Because it is common to perform arithmetic operations on a marker
  570. position, most of the arithmetic operations (including `+' and `-')
  571. accept markers as arguments.  In such cases, the marker stands for its
  572. current position.
  573.    Here are examples of creating markers, setting markers, and moving
  574. point to markers:
  575.      ;; Make a new marker that initially does not point anywhere:
  576.      (setq m1 (make-marker))
  577.           => #<marker in no buffer>
  578.      
  579.      ;; Set `m1' to point between the 99th and 100th characters
  580.      ;;   in the current buffer:
  581.      (set-marker m1 100)
  582.           => #<marker at 100 in markers.texi>
  583.      
  584.      ;; Now insert one character at the beginning of the buffer:
  585.      (goto-char (point-min))
  586.           => 1
  587.      (insert "Q")
  588.           => nil
  589.      
  590.      ;; `m1' is updated appropriately.
  591.      m1
  592.           => #<marker at 101 in markers.texi>
  593.      
  594.      ;; Two markers that point to the same position
  595.      ;;   are not `eq', but they are `equal'.
  596.      (setq m2 (copy-marker m1))
  597.           => #<marker at 101 in markers.texi>
  598.      (eq m1 m2)
  599.           => nil
  600.      (equal m1 m2)
  601.           => t
  602.      
  603.      ;; When you are finished using a marker, make it point nowhere.
  604.      (set-marker m1 nil)
  605.           => #<marker in no buffer>
  606. File: elisp,  Node: Predicates on Markers,  Next: Creating Markers,  Prev: Overview of Markers,  Up: Markers
  607. Predicates on Markers
  608. =====================
  609.    You can test an object to see whether it is a marker, or whether it
  610. is either an integer or a marker.  The latter test is useful in
  611. connection with the arithmetic functions that work with both markers
  612. and integers.
  613.  - Function: markerp OBJECT
  614.      This function returns `t' if OBJECT is a marker, `nil' otherwise.
  615.      Note that integers are not markers, even though many functions
  616.      will accept either a marker or an integer.
  617.  - Function: integer-or-marker-p OBJECT
  618.      This function returns `t' if OBJECT is an integer or a marker,
  619.      `nil' otherwise.
  620.  - Function: number-or-marker-p OBJECT
  621.      This function returns `t' if OBJECT is a number (either kind) or a
  622.      marker, `nil' otherwise.
  623. File: elisp,  Node: Creating Markers,  Next: Information from Markers,  Prev: Predicates on Markers,  Up: Markers
  624. Functions That Create Markers
  625. =============================
  626.    When you create a new marker, you can make it point nowhere, or point
  627. to the present position of point, or to the beginning or end of the
  628. accessible portion of the buffer, or to the same place as another given
  629. marker.
  630.  - Function: make-marker
  631.      This functions returns a newly created marker that does not point
  632.      anywhere.
  633.           (make-marker)
  634.                => #<marker in no buffer>
  635.  - Function: point-marker
  636.      This function returns a new marker that points to the present
  637.      position of point in the current buffer.  *Note Point::.  For an
  638.      example, see `copy-marker', below.
  639.  - Function: point-min-marker
  640.      This function returns a new marker that points to the beginning of
  641.      the accessible portion of the buffer.  This will be the beginning
  642.      of the buffer unless narrowing is in effect.  *Note Narrowing::.
  643.  - Function: point-max-marker
  644.      This function returns a new marker that points to the end of the
  645.      accessible portion of the buffer.  This will be the end of the
  646.      buffer unless narrowing is in effect.  *Note Narrowing::.
  647.      Here are examples of this function and `point-min-marker', shown in
  648.      a buffer containing a version of the source file for the text of
  649.      this chapter.
  650.           (point-min-marker)
  651.                => #<marker at 1 in markers.texi>
  652.           (point-max-marker)
  653.                => #<marker at 15573 in markers.texi>
  654.           
  655.           (narrow-to-region 100 200)
  656.                => nil
  657.           (point-min-marker)
  658.                => #<marker at 100 in markers.texi>
  659.           (point-max-marker)
  660.                => #<marker at 200 in markers.texi>
  661.  - Function: copy-marker MARKER-OR-INTEGER
  662.      If passed a marker as its argument, `copy-marker' returns a new
  663.      marker that points to the same place and the same buffer as does
  664.      MARKER-OR-INTEGER.  If passed an integer as its argument,
  665.      `copy-marker' returns a new marker that points to position
  666.      MARKER-OR-INTEGER in the current buffer.
  667.      If passed an integer argument less than 1, `copy-marker' returns a
  668.      new marker that points to the beginning of the current buffer.  If
  669.      passed an integer argument greater than the length of the buffer,
  670.      `copy-marker' returns a new marker that points to the end of the
  671.      buffer.
  672.      An error is signaled if MARKER is neither a marker nor an integer.
  673.           (setq p (point-marker))
  674.                => #<marker at 2139 in markers.texi>
  675.           
  676.           (setq q (copy-marker p))
  677.                => #<marker at 2139 in markers.texi>
  678.           
  679.           (eq p q)
  680.                => nil
  681.           
  682.           (equal p q)
  683.                => t
  684.           
  685.           (copy-marker 0)
  686.                => #<marker at 1 in markers.texi>
  687.           
  688.           (copy-marker 20000)
  689.                => #<marker at 7572 in markers.texi>
  690. File: elisp,  Node: Information from Markers,  Next: Changing Markers,  Prev: Creating Markers,  Up: Markers
  691. Information from Markers
  692. ========================
  693.    This section describes the functions for accessing the components of
  694. a marker object.
  695.  - Function: marker-position MARKER
  696.      This function returns the position that MARKER points to, or `nil'
  697.      if it points nowhere.
  698.  - Function: marker-buffer MARKER
  699.      This function returns the buffer that MARKER points into, or `nil'
  700.      if it points nowhere.
  701.           (setq m (make-marker))
  702.                => #<marker in no buffer>
  703.           (marker-position m)
  704.                => nil
  705.           (marker-buffer m)
  706.                => nil
  707.           
  708.           (set-marker m 3770 (current-buffer))
  709.                => #<marker at 3770 in markers.texi>
  710.           (marker-buffer m)
  711.                => #<buffer markers.texi>
  712.           (marker-position m)
  713.                => 3770
  714.    Two distinct markers are considered `equal' (even though not `eq')
  715. to each other if they have the same position and buffer, or if they
  716. both point nowhere.
  717. File: elisp,  Node: Changing Markers,  Next: The Mark,  Prev: Information from Markers,  Up: Markers
  718. Changing Marker Positions
  719. =========================
  720.    This section describes how to change the position of an existing
  721. marker.  When you do this, be sure you know whether the marker is used
  722. outside of your program, and, if so, what effects will result from
  723. moving it--otherwise, confusing things may happen in other parts of
  724. Emacs.
  725.  - Function: set-marker MARKER POSITION &optional BUFFER
  726.      This function moves MARKER to POSITION in BUFFER.  If BUFFER is
  727.      not provided, it defaults to the current buffer.
  728.      If POSITION is less than 1, `set-marker' moves MARKER to the
  729.      beginning of the buffer.  If POSITION is greater than the size of
  730.      the buffer, `set-marker' moves marker to the end of the buffer.
  731.      If POSITION is `nil' or a marker that points nowhere, then MARKER
  732.      is set to point nowhere.
  733.      The value returned is MARKER.
  734.           (setq m (point-marker))
  735.                => #<marker at 4714 in markers.texi>
  736.           (set-marker m 55)
  737.                => #<marker at 55 in markers.texi>
  738.           (setq b (get-buffer "foo"))
  739.                => #<buffer foo>
  740.           (set-marker m 0 b)
  741.                => #<marker at 1 in foo>
  742.  - Function: move-marker MARKER POSITION &optional BUFFER
  743.      This is another name for `set-marker'.
  744. File: elisp,  Node: The Mark,  Next: The Region,  Prev: Changing Markers,  Up: Markers
  745. The Mark
  746. ========
  747.    One special marker in each buffer is designated "the mark".  It
  748. records a position for the user for the sake of commands such as `C-w'
  749. and `C-x TAB'.  Lisp programs should set the mark only to values that
  750. have a potential use to the user, and never for their own internal
  751. purposes.  For example, the `replace-regexp' command sets the mark to
  752. the value of point before doing any replacements, because this enables
  753. the user to move back there conveniently after the replace is finished.
  754.    Many commands are designed so that when called interactively they
  755. operate on the text between point and the mark.  If you are writing such
  756. a command, don't examine the mark directly; instead, use `interactive'
  757. with the `r' specification.  This provides the values of point and the
  758. mark as arguments to the command in an interactive call, but permits
  759. other Lisp programs to specify arguments explicitly.  *Note Interactive
  760. Codes::.
  761.    Each buffer has its own value of the mark that is independent of the
  762. value of the mark in other buffers.  When a buffer is created, the mark
  763. exists but does not point anywhere.  We consider this state as "the
  764. absence of a mark in that buffer."
  765.    Once the mark "exists" in a buffer, it normally never ceases to
  766. exist.  However, it may become "inactive", if Transient Mark mode is
  767. enabled.  The variable `mark-active', which is always local in all
  768. buffers, indicates whether the mark is active: non-`nil' means yes.  A
  769. command can request deactivation of the mark upon return to the editor
  770. command loop by setting `deactivate-mark' to a non-`nil' value (but
  771. this causes deactivation only if Transient Mark mode is enabled).
  772.    The main motivation for using Transient Mark mode is that this mode
  773. also enables highlighting of the region when the mark is active.  *Note
  774. Display::.
  775.    In addition to the mark, each buffer has a "mark ring" which is a
  776. list of markers containing previous values of the mark.  When editing
  777. commands change the mark, they should normally save the old value of the
  778. mark on the mark ring.  The variable `mark-ring-max' specifies the
  779. maximum number of entries in the mark ring; once the list becomes this
  780. long, adding a new element deletes the last element.
  781.  - Function: mark &optional FORCE
  782.      This function returns the current buffer's mark position as an
  783.      integer.
  784.      If the mark is inactive, `mark' normally signals an error.
  785.      However, if FORCE is non-`nil', then `mark' returns the mark
  786.      position anyway--or `nil', if the mark is not yet set for this
  787.      buffer.
  788.  - Function: mark-marker
  789.      This function returns the current buffer's mark.  This is the very
  790.      marker that records the mark location inside Emacs, not a copy.
  791.      Therefore, changing this marker's position will directly affect
  792.      the position of the mark.  Don't do it unless that is the effect
  793.      you want.
  794.           (setq m (mark-marker))
  795.                => #<marker at 3420 in markers.texi>
  796.           (set-marker m 100)
  797.                => #<marker at 100 in markers.texi>
  798.           (mark-marker)
  799.                => #<marker at 100 in markers.texi>
  800.      Like any marker, this marker can be set to point at any buffer you
  801.      like.  We don't recommend that you make it point at any buffer
  802.      other than the one of which it is the mark.  If you do, it will
  803.      yield perfectly consistent, but rather odd, results.
  804.  - Function: set-mark POSITION
  805.      This function sets the mark to POSITION, and activates the mark.
  806.      The old value of the mark is *not* pushed onto the mark ring.
  807.      *Please note:* Use this function only if you want the user to see
  808.      that the mark has moved, and you want the previous mark position to
  809.      be lost.  Normally, when a new mark is set, the old one should go
  810.      on the `mark-ring'.  For this reason, most applications should use
  811.      `push-mark' and `pop-mark', not `set-mark'.
  812.      Novice Emacs Lisp programmers often try to use the mark for the
  813.      wrong purposes.  The mark saves a location for the user's
  814.      convenience.  An editing command should not alter the mark unless
  815.      altering the mark is part of the user-level functionality of the
  816.      command.  (And, in that case, this effect should be documented.)
  817.      To remember a location for internal use in the Lisp program, store
  818.      it in a Lisp variable.  For example:
  819.           (let ((beg (point)))
  820.             (forward-line 1)
  821.             (delete-region beg (point))).
  822.  - Function: push-mark &optional POSITION NOMSG ACTIVATE
  823.      This function sets the current buffer's mark to POSITION, and
  824.      pushes a copy of the previous mark onto `mark-ring'.  If POSITION
  825.      is `nil', then the value of point is used.  `push-mark' returns
  826.      `nil'.
  827.      The function `push-mark' normally *does not* activate the mark.
  828.      To do that, specify `t' for the argument ACTIVATE.
  829.      A `Mark set' message is displayed unless NOMSG is non-`nil'.
  830.  - Function: pop-mark
  831.      This function pops off the top element of `mark-ring' and makes
  832.      that mark become the buffer's actual mark.  This does not move
  833.      point in the buffer, and it does nothing if `mark-ring' is empty.
  834.      It deactivates the mark.
  835.      The return value is not meaningful.
  836.  - User Option: transient-mark-mode
  837.      This variable if non-`nil' enables Transient Mark mode, in which
  838.      every buffer-modifying primitive sets `deactivate-mark'.  The
  839.      consequence of this is that commands that modify the buffer
  840.      normally make the mark inactive.
  841.  - Variable: deactivate-mark
  842.      If an editor command sets this variable non-`nil', then the editor
  843.      command loop deactivates the mark after the command returns, but
  844.      only if Transient Mark mode is enabled.
  845.  - Function: deactivate-mark
  846.      This function deactivates the mark, but only if Transient Mark mode
  847.      is enabled.
  848.  - Variable: mark-active
  849.      The mark is active when this variable is non-`nil'.  This variable
  850.      is always local in each buffer.
  851.  - Variable: activate-mark-hook
  852.  - Variable: deactivate-mark-hook
  853.      These normal hooks are run, respectively, when the mark becomes
  854.      active and when it becomes inactive.  The hook
  855.      `activate-mark-hook' is also run at the end of a command if the
  856.      mark is active and the region may have changed.
  857.  - Variable: mark-ring
  858.      The value of this buffer-local variable is the list of saved former
  859.      marks of the current buffer, most recent first.
  860.           mark-ring
  861.           => (#<marker at 11050 in markers.texi>
  862.               #<marker at 10832 in markers.texi>
  863.               ...)
  864.  - User Option: mark-ring-max
  865.      The value of this variable is the maximum size of `mark-ring'.  If
  866.      more marks than this are pushed onto the `mark-ring', `push-mark'
  867.      discards an old mark when it adds a new one.
  868. File: elisp,  Node: The Region,  Prev: The Mark,  Up: Markers
  869. The Region
  870. ==========
  871.    The text between point and the mark is known as "the region".
  872. Various functions operate on text delimited by point and the mark, but
  873. only those functions specifically related to the region itself are
  874. described here.
  875.  - Function: region-beginning
  876.      This function returns the position of the beginning of the region
  877.      (as an integer).  This is the position of either point or the mark,
  878.      whichever is smaller.
  879.      If the mark does not point anywhere, an error is signaled.
  880.  - Function: region-end
  881.      This function returns the position of the end of the region (as an
  882.      integer).  This is the position of either point or the mark,
  883.      whichever is larger.
  884.      If the mark does not point anywhere, an error is signaled.
  885.    Few programs need to use the `region-beginning' and `region-end'
  886. functions.  A command designed to operate on a region should normally
  887. use `interactive' with the `r' specification to find the beginning and
  888. end of the region.  This lets other Lisp programs specify the bounds
  889. explicitly as arguments.  (*Note Interactive Codes::.)
  890. File: elisp,  Node: Text,  Next: Searching and Matching,  Prev: Markers,  Up: Top
  891.    This chapter describes the functions that deal with the text in a
  892. buffer.  Most examine, insert, or delete text in the current buffer,
  893. often in the vicinity of point.  Many are interactive.  All the
  894. functions that change the text provide for undoing the changes (*note
  895. Undo::.).
  896.    Many text-related functions operate on a region of text defined by
  897. two buffer positions passed in arguments named START and END.  These
  898. arguments should be either markers (*note Markers::.) or numeric
  899. character positions (*note Positions::.).  The order of these arguments
  900. does not matter; it is all right for START to be the end of the region
  901. and END the beginning.  For example, `(delete-region 1 10)' and
  902. `(delete-region 10 1)' are equivalent.  An `args-out-of-range' error is
  903. signaled if either START or END is outside the accessible portion of
  904. the buffer.  In an interactive call, point and the mark are used for
  905. these arguments.
  906.    Throughout this chapter, "text" refers to the characters in the
  907. buffer, together with their properties (when relevant).
  908. * Menu:
  909. * Near Point::       Examining text in the vicinity of point.
  910. * Buffer Contents::  Examining text in a general fashion.
  911. * Comparing Text::   Comparing substrings of buffers.
  912. * Insertion::        Adding new text to a buffer.
  913. * Commands for Insertion::  User-level commands to insert text.
  914. * Deletion::         Removing text from a buffer.
  915. * User-Level Deletion::     User-level commands to delete text.
  916. * The Kill Ring::    Where removed text sometimes is saved for later use.
  917. * Undo::             Undoing changes to the text of a buffer.
  918. * Maintaining Undo:: How to enable and disable undo information.
  919.             How to control how much information is kept.
  920. * Filling::          Functions for explicit filling.
  921. * Margins::          How to specify margins for filling commands.
  922. * Auto Filling::     How auto-fill mode is implemented to break lines.
  923. * Sorting::          Functions for sorting parts of the buffer.
  924. * Columns::          Computing horizontal positions, and using them.
  925. * Indentation::      Functions to insert or adjust indentation.
  926. * Case Changes::     Case conversion of parts of the buffer.
  927. * Text Properties::  Assigning Lisp property lists to text characters.
  928. * Substitution::     Replacing a given character wherever it appears.
  929. * Transposition::    Swapping two portions of a buffer.
  930. * Registers::        How registers are implemented.  Accessing the text or
  931.                        position stored in a register.
  932. * Change Hooks::     Supplying functions to be run when text is changed.
  933.